package algotithm.leetcode.twopoint.test719;

/**
 * @author 25068
 * @Date 2021/5/24 8:46
 * @Title 713. 乘积小于K的子数组
 */
public class Solution {

    public static void main(String[] args) {
        int[] nums = {10,5,2,6};
        int k = 100;
        Solution solution = new Solution();
        int ans = solution.numSubarrayProductLessThanK(nums, k);
        System.out.println(ans);
    }

    public int numSubarrayProductLessThanK(int[] nums, int k) {
        int ans = 0;
        int res = 1;
        int l = 0;
        for (int i = 0; i < nums.length; i++) {
            res *= nums[i];
            while (res >= k) {
                res /= nums[l++];
            }
            ans += i - l + 1;
        }
        return ans;
    }

}
